package com.gsq.controller;

import com.gsq.common.pojo.User;
import com.gsq.common.vo.PageResult;
import com.gsq.common.vo.SysResult;
import com.gsq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private UserService userService;

    /*  数据展现    */
    @GetMapping("/getUserList")
    public SysResult getUserList(PageResult pageResult){
        pageResult = userService.getUserList(pageResult);
        return SysResult.success(pageResult);
    }

    /* 增加用户 */
    @PostMapping("/addUser")
    public SysResult addUser(@RequestBody User user){
        userService.addUser(user);
        return SysResult.success();
    }
    /* 修改用户状态*/
    @PutMapping("/userValid/{id}/{userStatus}")
    public SysResult updatedValid(User user){
        userService.updatedValid(user);
        return SysResult.success();
    }
    /* 修改用户信息 */
    @PutMapping("/updateUser")
    public SysResult updateUser(@RequestBody User user){
        userService.updateUser(user);
        return SysResult.success();
    }
    /* 根据id反馈用户信息 */
    @GetMapping("/user/{id}")
    public SysResult findUser(@PathVariable Integer id){
        User user = userService.findUser(id);
        return SysResult.success(user);
    }
    /* 删除用户 */
    @DeleteMapping("/user/{id}")
    public SysResult deleteUser(@PathVariable Integer id){
        userService.deleteUser(id);
        return SysResult.success();
    }
}
